package com.yuan.gather.controller;

import com.yuan.gather.entity.Asset;
import com.yuan.gather.repository.AssetRepository;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Api(tags = "测试接口类")
@RestController
@RequestMapping("/api/test")
public class TestController {

    /**
     * 资产数据访问接口
     */
    @Autowired
    private AssetRepository assetRepository;

    @ApiOperation("测试接口")
    @GetMapping(value = "/test")
    public Map<String, Object> Test() {
        List<Asset> assetList = assetRepository.findAll();

        Asset assetTemp = assetRepository.findById(100).orElse(null);

        Asset asset =new Asset();
        asset.setIp("1.1.1.1");
        asset.setName("测试");
        List<String> tags = new ArrayList<>();
        tags.add("1");
        tags.add("2");
        tags.add("3");
        asset.setTags(tags);
        Map<String, Object> extra = new HashMap<>();
        extra.put("a","aaa");
        extra.put("b","bbb");
        asset.setExtra(extra);
        assetRepository.save(asset);



        return null;
    }

}
